<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <!--  bbb.com -->
  用户：<input type="text" id="user"><br>
  密码：<input type="text" id="pass"><br>
  <input type="button" value="登录" id="btn1">
</body>
<script>
    /* $('#btn1').click(function(){
        $.ajax({
            type: "get",
            url: "http://auth.aaa.com:8080/login",
            data: {
                user:$('#user').val(),
                pass:$('#pass').val(),
            },
            dataType: "json",
            success: function (response) {
                if(response.err){
                    console.log(response.msg)
                }else{
                    console.log(response);
                    document.cookie=`token=${response.token}`
                }
            },
            error(){
                alert('error')
            }
        });
    }) */
    let query={};
    let token = $.cookie('token')   //获取token

    if(window.location.search){
        window.location.search.substring(1).split('&').forEach(item=>{
            let [key,value]=item.split('=');
            query[key]=value;
        })
    }

    if(query['token']){
        $.cookie('token',query[key])
    }else{
        // 先现在cookie.js 然后使用
        if(!$.cookie('token')){
            window.location=`http://auth.aaa.com:8080/login?user=blue&pass=123456&src=${encodeURIComponent('http://www.bbb.com:8080/1.html')}`;
        }
    }



    

</script>
</html>